package com.tywj.navigation.popupwindow

import android.content.Context
import android.content.DialogInterface
import android.os.Bundle
import androidx.annotation.NonNull
import androidx.annotation.Nullable
import androidx.appcompat.app.AlertDialog
import com.tywj.lib.core.common.extension.load
import com.tywj.lib.core.common.extension.onClick
import com.tywj.lib.core.common.util.ToastUtil
import com.tywj.navigation.R
import kotlinx.android.synthetic.main.navigation_pop_img_layout.*

/**
 * <pre>
 *     author : June Yang
 *     time   : 2020/05/12
 *     desc   :查看实景自定义对话框
 *     version: 1.9.0
 * </pre>
 */
@Suppress("RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS")
class MapDetailsPopUpImgView : AlertDialog {

    private var path = ""
    private var info = ""

    constructor(
        @NonNull context: Context,
        path: String = "",
        info: String = ""
    ) : super(context) {
        this.path = path
        this.info = info
    }


    protected constructor(
        @NonNull context: Context,
        cancelable: Boolean,
        @Nullable cancelListener: DialogInterface.OnCancelListener?,
        path: String = ""
    ) : super(context, cancelable, cancelListener) {
        this.path = path
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.navigation_pop_img_layout)

        val windowManager = window.windowManager
        val screenWidth = windowManager.defaultDisplay.width
        val screenHeight = windowManager.defaultDisplay.height
        val attributes = window.attributes
        // 设置窗口背景透明度
        attributes.alpha = 1f
        // 设置窗口宽高为屏幕的三分之一（为了更好地适配，请别直接写死）
        attributes.width = 4 * screenWidth / 5
        attributes.height = 2 * screenHeight / 3
        window.attributes = attributes
        window.setWindowAnimations(R.style.take_photo_anim)

        loadImage()
        tvShowInfo.onClick {
            if (info.isNotEmpty()) {
//                val intent = Intent(context, WebActivity::class.java)
//                intent.putExtra("url", info)
//                context.startActivity(intent)
                ToastUtil.shortToast("web")
            } else {
                ToastUtil.shortToast("暂无详情")
            }
        }
    }

    private fun loadImage() {
        ivPopImg.load(path, R.drawable.common_icon_img_bording, R.drawable.common_icon_img_bording)
    }
}